<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>H+ 后台主题UI框架 - FooTable</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="@{/asserts/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/asserts/css/font-awesome.min.css}" rel="stylesheet">
    <link th:href="@{/asserts/css/plugins/footable/footable.core.css}" rel="stylesheet">
    <link href="asserts/css/bootstrap-select.min.css" rel="stylesheet"
          th:href="@{/asserts/css/bootstrap-select.min.css}">

    <link th:href="@{/asserts/css/animate.min.css}" rel="stylesheet">
    <link th:href="@{/asserts/css/style.min.css}" rel="stylesheet">
    <link th:href="@{/asserts/css/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

</div>
<script th:src="@{/asserts/js/jquery.min.js}"></script>
<script th:src="@{/asserts/js/bootstrap.min.js}"></script>
<script th:src="@{/asserts/js/plugins/footable/footable.all.min.js}"></script>
<script th:src="@{/asserts/js/content.min.js}"></script>
<script th:src="@{/asserts/js/layer/layer.min.js}" type="text/javascript"></script>
<script th:src="@{/asserts/js/bootstrap-table/bootstrap-table.min.js?v=1}"></script>
<script th:src="@{/asserts/js/bootstrap-table/locale/bootstrap-table-zh-CN.js}"></script>
<script src="asserts/js/bootstrap-select.min.js" th:src="@{/asserts/js/bootstrap-select.min.js}"
        type="text/javascript"></script>
<script th:src="@{/asserts/js/ajaxfileupload.js}"></script>
<script th:src="@{/asserts/js/tree-view/js/bootstrap-treeview-cl.js?v=1.1}" type="text/javascript"></script>
<script th:replace="common/myJs::myCommonJs"></script>
<script th:inline="javascript">
    $(function () {
        getTree();
    });

    function getTree() {
        let url = 'findTree'
        $.ajax({
            url: url,
            type: "get",
            success: function (data) {
                data = eval('(' + data + ')');
                resolve(data)
            },
            error: function (data) {
            }
        });
    }

    function resolve(data) {
        $('#tree').treeview({
            collapseIcon: "fa fa-minus",
            nodeIcon: "fa fa-building-o",
            emptyIcon: "",
            showIcon: true,
            levels: 2,
            expandIcon: "fa fa-plus",
            data: data,
            showTags: true,
            onNodeExpanded: function (event, data) {
                let url = 'getByParent'
                let id = data['nodeId'];		//获取节点的nodeid （nodeid是treeview自动生成的，每个节点不同）
                $.ajax({					//异步加载当前节点的子节点数据
                    type: "post",
                    url: url,
                    async: false,
                    dataType: 'json',
                    data: 'parentId=' + data['id'],
                    success: function (result) {
                        let arr = [];
                        $("#tree").treeview("deleteChildrenNode", id);
                        for (var i = 0; i < result.length; i++) {
                            //result[i]的格式如下图
                            arr.push(result[i]);
                        }
                        $("#tree").treeview("addNode", [id, {node: arr, silent: true}]);
                    }
                });
            },
            onNodeSelected: function (event, data) {
                $("#pid").val(data.id);
                createTable();
            }
        });
    }

    function createTable() {
        let url = [[@{'/orgbase/list'}]];
        $("#table").bootstrapTable('destroy');
        $("#table").bootstrapTable({
            url: url,        //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            contentType: "application/x-www-form-urlencoded",
            pagination: true,                   //是否显示分页（*）
            cache: false,
            pageSize: 10,//每页一条数据
            striped: true,  //表格显示条纹
            dataField: "list",
            queryParamsType: "undefined",
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    unitname: $('#unitname').val(),
                    superiormanagementunitid:  $("#pid").val()
                };
                return param;
            },
            sidePagination: 'server',
            pageNumber: 1,
            columns: [{
                field: "uuid",
                visible: false
            }, {
                field: "unitname",
                title: "单位名称"
            }, {
                field: "creditcode",
                title: "统一社会信用代码"
            },{
                field: "domain",
                title: "境内外标志"
            }, {
                field: "unittype",
                title: "单位类型"
            }, {
                field: "enterprisetype",
                title: "企业类型"
            }, {
                field: "cz",
                title: "操作",
                width: "20%",
                formatter: function (value, row) {
                    var editHtml = '<a href="javascript:;" class="btn btn-success edit"><i class="fa fa-pencil"> </i> 编辑</a>&nbsp;';
                    var delHtml = '<a href="javascript:;" class="btn btn-danger del"><i class="fa fa-trash"> </i> 删除</a>&nbsp;';

                    var buttonhtml = editHtml + delHtml;
                    return buttonhtml;
                },
                events: {
                    'click .edit': function (e, value, row, index) {
                        var id = row.id;
                        let url = [[@{'/orgbase/goedit?id='}]] + id
                        location.href = url;
                    },
                    'click .del': function (e, value, row, index) {
                        var id = row.id;
                        var url = [[@{'/orgbase/delete'}]];

                        $('#confirmModal').modal("show");
                        $("#confirmDelete").click(function () {
                            $.ajax({
                                url: url,
                                data: 'id=' + id,
                                type: "post",
                                success: function (data) {
                                    createTable();
                                }
                            });
                            $('#confirmModal').modal("hide");
                        });
                    }
                }
            }]
        });
    }

</script>
    <div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>企业树</h5>
                </div>
                <div class="ibox-content table-responsive">
                    <div class="col-sm-12 " id="tree">
                    </div>
                </div>

            </div>
        </div>
        <div class="col-sm-8 orgDoTable">
            <div class="row">
                <div class="col-sm-4">
                    <input class="form-control form-control-sm search" id="unitname" placeholder="企业名称"
                           th:placeholder="企业名称" type="text">
                    <input id="pid" type="hidden">
                </div>
                <div class="col-sm-4">
                    <a class="btn btn-sm btn-primary badge-pill" href="javascript:createTable()"><i class="fa fa-search"> </i>
                        [[#{message.search}]]</a>
                    <a class="btn btn-sm btn-default badge-pill" href="javascript:resetTable()"><i class="fa fa-circle-o"> </i>
                        [[#{message.reset}]]</a>
                </div>
            </div>
            <div>
                <hr style="margin: 15px 0px 5px 0px "/>

                <div class="table-responsive">
                    <table id="table">
                    </table>
                </div>
            </div>
        </div>
    </div>
    </div>

</body>

</html>
